import Http from './http';
import { LocalConf, SrvConf } from '../conf/http.conf';

let httpUntil = new Http({ type: 'fetch' });

httpUntil.setOvertime(30 * 1000).setHeader({
  Accept: 'application/json',
  invoke_source: SrvConf.invoke_source
}).setBodyType('urlSearch');

export default {
  async setHeader({ key, val }) {
    httpUntil.setHeader(key, val);
  },
  async get(url, params = {}) {
    let res = await httpUntil.setUrl(LocalConf.baseURL + url).setMethod('GET').setBody(params).send()
      .then(data => data)
      .catch(error => {
        console.warn('=> catch: ', error);
      });
    return res;
  },
  async post(url, params = {}) {
    let res = await httpUntil.setUrl(LocalConf.baseURL + url).setMethod('POST').setBody(params).send()
      .then(data => data)
      .catch(error => {
        console.warn('=> catch: ', error);
      });
    return res;
  }
};
